﻿

namespace N_dimenslArr
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using MapleRock.P2PEmulator.Core;
    using Tao.FreeGlut;
    using Tao.OpenGl;
    using Tao.Platform;

    public class Node
    {
        private string ipAddress;

        private string position;

        private uint id;

        public Node()
        {
            this.ipAddress = null;
            this.position = null;
            this.id = 0;
            this.PositionNumeric = new double[2];
        }

        public Node(string ipAddress, string position, uint id)
        {
            Debug.Assert(ipAddress != null, "ipAddress != null");
            Debug.Assert(position != null, "position != null");
            Debug.Assert(id != 0, "id != null");
            string from = position.Remove(position.IndexOf(' '));
            string to = position.Remove(0, position.IndexOf(' '));
            this.PositionNumeric[0] = System.Convert.ToDouble(from);
            this.PositionNumeric[1] = System.Convert.ToDouble(to);
            this.ipAddress = ipAddress;
            this.id = id;
            this.position = position;
        }

        public double[] PositionNumeric { get; set; }

        public static Node FromXmlNode(XmlPeer xmlPeer)
        {
            Node node = new Node();
            node.ipAddress = xmlPeer.IpAddress;
            node.position = xmlPeer.Position;
            node.id = xmlPeer.Id;
            node.PositionNumeric[0] = System.Convert.ToDouble(node.position.Remove(node.position.IndexOf(' ')));
            node.PositionNumeric[1] = System.Convert.ToDouble(node.position.Remove(0, node.position.IndexOf(' ')));
            return node;
        }

        public void Render()
        {
            Gl.glPushAttrib(Gl.GL_POINT);

            Gl.glPointSize(3);

            Gl.glBegin(Gl.GL_POINTS);

            Gl.glVertex3d(this.PositionNumeric[0], this.PositionNumeric[1], 0);

            Gl.glEnd();

            Gl.glPopAttrib();
        }
    }
}
